<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>e网批发管理后台</title>
	<?php 
  include("common/conn.php"); 
  include('./tool/UpFileTool.class.php');
  if($_SESSION['shopid']==""){
    echo "<script>window.location.href='login.php';</script>";
  } 

	if($_GET['action']=="ok")
	{
		$state=2;
		$srat1=mysql_query("update goodsorders set kuaidi='".$_POST['kuaidi']."',danhao='".$_POST['danhao']."',state='".$state."' where ordersid='".$_REQUEST['id']."'");
	    // 调用信息推送接口
	    $url = "http://120.24.0.10/xzpf/api/jpush/jpush.php?state=".$state."&ordersid=".$_POST[id];
	    file_get_contents($url);
	    // 调用信息推送接口 end
	}


	if($_GET[wancheng]=="ok"){
		$state=3;
		$srat=mysql_query("update goodsorders set state='".$state."' where ordersid='".$_GET[id]."'");

	    // 调用信息推送接口
	    $url = "http://120.24.0.10/xzpf/api/jpush/jpush.php?state=".$state."&ordersid=".$_GET[id];
	    file_get_contents($url);
	    // 调用信息推送接口 end
	}
  // 填写快递信息 
	if(isset($_POST[kuaidi])){
		$state=2;
		$srat=mysql_query("update goodsorders set kuaidi='".$_POST[kuaidi]."',danhao='".$_POST[danhao]."',state='".$state."' where ordersid='".$_POST[ordersid]."'");

	    // 调用信息推送接口
	    $url = "http://120.24.0.10/xzpf/api/jpush/jpush.php?state=".$state."&ordersid=".$_POST[ordersid];
	    file_get_contents($url);
	    // 调用信息推送接口 end	

      // 查找订单自动确认收货时间 
      $query = mysql_query("select confirm_time from categroy_type where id=(select categroy_type_id from categroy where cateid=(select leimu from shop where shopid=(select shopid from goodsorders where ordersid=".$_POST[ordersid].")))");
      $categroy_type = mysql_fetch_assoc($query);
      $confirm_time = $categroy_type[confirm_time];
      // 查找订单自动确认收货时间 end
      // 定时器
      $url = "http://120.24.0.10/xzpf/changeAfterTime/changeOrderState.php?ordersid=".$_POST[ordersid]."";
      $start_date = date("Y-m-d",strtotime(''.$confirm_time.'days'));
      $start_hour = date("H");
      $start_minute = date("i");
      $tag = 'setOrderState';
      $loop = 1;

      $apiUrl = "http://120.24.0.10/unitask/core/func.add.php?url=".$url."&start_date=".$start_date."&start_hour=".$start_hour."&start_minute=".$start_minute."&tag=".$tag."&loop=".$loop."";
      file_get_contents($apiUrl);
      // 定时器 end
	    
		echo "<script>alert('发货成功');window.location.href='index.php?state=".$state."'</script>";
	}
  // 填写快递信息 end
	// 查找快递公司
	  $query=mysql_query("select * from express_delivery");
	  while ($row=mysql_fetch_assoc($query)) {
	    $express[]=$row;
	  }
	// 查找快递公司 end

  // 填写回收地址 
  if (isset($_POST['address'])) {
    $address = $_POST['address'];
    $ordersid = $_POST['ordersid'];
    $state2 = 2;
    $datetime = date("Y-m-d H:i:s");
    $query = mysql_query("UPDATE tuihuo set address='".$address."',state = ".$state2.",2time='".$datetime."' where ordersid=".$ordersid);
    echo "<script>alert('审核通过');window.location.href='index.php?state=4'</script>";
  }
  // 填写回收地址 end

// 商家拒绝退货 
if (isset($_POST['shop_comment'])) {
  if ($_FILES['shop_images']['name'][0] != '') {
    $UpFileTool=new UpFileTool('shop_images');
    $UpFileTool->multiImage($w=500, $h=500,$sumbimage='../sumbimage', $srcimage='../srcimage');
    $images=$UpFileTool->multiSumbImage;
    $srcimages=$UpFileTool->multiSrcImage;
  }

  $shop_comment = $_POST['shop_comment'];
  $ordersid = $_POST['ordersid'];
  $state3 = 3;
  $datetime = date("Y-m-d H:i:s");
  $query = mysql_query("UPDATE tuihuo set shop_comment='".$shop_comment."',shop_images='".$images."',shop_srcimages='".$srcimages."',state = ".$state3.",2time='".$datetime."' where ordersid=".$ordersid);
  echo "<script>alert('已拒绝接单');window.location.href='index.php?state=4'</script>";
}
// 商家拒绝退货 end

	// 取消退货 
	if ($_REQUEST['act'] == 'cancel') {
	  $query = mysql_query("select orderstate from tuihuo where ordersid=".$_REQUEST['ordersid']);
	  $tuihuo = mysql_fetch_assoc($query);
	  $orderstate = $tuihuo['orderstate'];

	  $query = mysql_query("DELETE FROM tuihuo where ordersid=".$_REQUEST['ordersid']);
	  $query = mysql_query("UPDATE goodsorders set state='".$orderstate."' where ordersid=".$_REQUEST['ordersid']);
	  if (mysql_affected_rows()>0) {
	    echo "<script>alert('取消退货成功');window.location.href='index.php?state=".$orderstate."'</script>";
	  }else{
	    echo "<script>alert('取消退货失败');window.location.href='index.php?state=".$orderstate."'</script>";
	  }
	}
	// 取消退货 end

// 改变订单状态 
if ($_REQUEST['act'] == 'change') {
  $state = $_REQUEST['state'];
  $ordersid = $_REQUEST['ordersid'];
  $query = mysql_query("UPDATE goodsorders set state=".$state." where ordersid=".$ordersid);
  $url = 'index.php?state='.$state;
  if (mysql_affected_rows()>0) {
    echo "<script>alert('更新成功');window.location.href='".$url."'</script>";
  }else{
    echo "<script>alert('更新失败');window.location.href='".$url."'</script>";
  }
}
// 改变订单状态 end

// 改变退货状态 
if ($_REQUEST['act'] == 'change_tuihuo') {
  $state = $_REQUEST['state'];
  $ordersid = $_REQUEST['ordersid'];
  $query = mysql_query("UPDATE tuihuo set state=".$state." where ordersid=".$ordersid);
  $url = 'index.php?state=4';
  if (mysql_affected_rows()>0) {
    echo "<script>alert('更新成功');window.location.href='".$url."'</script>";
  }else{
    echo "<script>alert('更新失败');window.location.href='".$url."'</script>";
  }
}
// 改变退货状态 end
	?>
	<script type="text/javascript" src="js/jquery.min.js"></script>
	<link href="css/styles.css" rel="stylesheet" type="text/css" />
	<link href="css/style2.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<!--header-->
	<?php include("common/header.php");?>
	<!--header end-->
	<div id="sub_nav">
		<div id="subnav_wrap" class="container_12">
			<div id="subnav" class=" grid_12">
        <ul>

          <li><a href="index.php" <?php if($_GET['state']==""){echo 'class="sub_nav_active"';}?>>所有订单</a></li>
          <li><a href="index.php?state=0" <?php if($_GET['state']=="0"){echo 'class="sub_nav_active"';}?>>待付款</a></li>
          <li><a href="index.php?state=1" <?php if($_GET['state']=="1"){echo 'class="sub_nav_active"';}?>>待商家接单</a></li>
          <li><a href="index.php?state=8" <?php if($_GET['state']=="8"){echo 'class="sub_nav_active"';}?>>待发货</a></li>
          <li><a href="index.php?state=9" <?php if($_GET['state']=="9"){echo 'class="sub_nav_active"';}?>>商家拒绝接单</a></li>
          <li><a href="index.php?state=2" <?php if($_GET['state']=="2"){echo 'class="sub_nav_active"';}?>>待客户收货</a></li>
          <li><a href="index.php?state=3" <?php if($_GET['state']=="3"){echo 'class="sub_nav_active"';}?>>待客户评价</a></li> 
          <li><a href="index.php?state=4" <?php if($_GET['state']=="4"){echo 'class="sub_nav_active"';}?>>退货售后</a></li> 
          <li><a href="index.php?state=5" <?php if($_GET['state']=="5"){echo 'class="sub_nav_active"';}?>>交易完成</a></li>  
          <li><a href="index.php?state=6" <?php if($_GET['state']=="6"){echo 'class="sub_nav_active"';}?>>交易关闭</a></li>    
        </ul>

			</div>
		</div>
	</div>
	<div class="container_12">
		<?php 

		$rert=mysql_query("select * from goodsorders where ordersid ='".$_GET[id]."'"); 

		$sdg3=mysql_fetch_array($rert);


		$count2=mysql_query("select count(*) from car where  ordersid ='".$sdg3[ordersid]."'");

//获得订单记录总数
		$rs2=mysql_fetch_array($count2);
		$totalNumber2=$rs2[0];
		?>
		<div class="cy_mode" style="background: #fff; border:0px;">
			<strong>订单号：<?php echo $sdg3[numbers];?></strong>

    <?php if($sdg3['state']=="1" || $sdg3['state']=="7"){?>
    <div class="dr_in accept" >接受订单</div>
    <div class="dr_in refuse" >拒绝订单</div>
    <?php }else if($sdg3['state']=="0"){?>
    <div class="dr_in2">等待客户付款</div>
    <?php }else if($sdg3['state']=="3"){?>
    <div class="dr_in2">等待客户评价</div>

    <?php 
    }else if($sdg3['state']=="4"){?>
    <?php
      $query = mysql_query("select * from tuihuo where ordersid=".$sdg3[ordersid]);
      $tuihuo = mysql_fetch_assoc($query);
      // 海淘
      if ($sdg3['type'] == 0) {
        if ($tuihuo[state]==1) { ?>
          <?php if ($tuihuo['orderstate'] == 2 || $tuihuo['orderstate'] == 3) { ?>
            <div class="dr_in agree_return">同意退货</div>
          <?php }else{ ?>
            <div class="dr_in agree">同意退货</div>
          <?php } ?>
        
        <div class="dr_in refuse_return">拒绝退货</div>

        <?php }elseif ($tuihuo[state]==2) { ?>

        	<?php if ($tuihuo[orderstate]==2 || $tuihuo[orderstate]==3) { ?>
            <div class="dr_in2">待用户确认退货</div>
          <?php }else{ ?>
        		<div class="dr_in2">等待平台处理</div>
        	<?php } ?>

        <?php }elseif ($tuihuo[state]==3) { ?>
        <div class="dr_in2">商家拒绝退货</div>

        <?php }elseif ($tuihuo[state]==4) { ?>
        <div class="dr_in recover">确认回收</div>
        <?php }elseif ($tuihuo[state]==5) { ?>
        <div class="dr_in2">等待平台处理</div>
        <?php }elseif ($tuihuo[state]==6) { ?>
        <div class="dr_in2">退货完成</div>
        <?php } 
      // 快购
      }elseif ($sdg3['type'] == 1) {
		if ($tuihuo[state]==1) { ?>
        <div class="dr_in2">等待平台处理</div>
        <?php } 
      }
	?>
    <?php }else if($sdg3['state']=="5"){?>
    <div class="dr_in2">交易完成</div>
    <?php }else if($sdg3['state']=="8"){?>
    <div class="dr_in delivery">发货</div>
    <?php }else if($sdg3['state']=="9"){?>
    <div class="dr_in2">等待平台处理</div>
    <?php }else if($sdg3['state']=="6"){?>
    <div class="dr_in2">交易关闭</div>
    <?php }else{?>
    <div class="dr_in2">待客户收货</div>
    <?php }?>
		</div>
		<?php 
		$state=1;
		$rert2=mysql_query("select * from car where  ordersid ='".$sdg3[ordersid]."' order by carid desc"); 
		while($sdg2=mysql_fetch_array($rert2))

		{	

			$rert=mysql_query("select * from goods where  goodsid ='".$sdg2[goodsid]."'"); 
			$sdg=mysql_fetch_array($rert);

			?>
			<div class="cy_mode" style="background:#FFFFFF; margin-top:0px;">
				<div class="dr_mimg">
					<?php
					$ime=$sdg[images];
					$de = array();
					$de=explode("," ,$ime);
					$images=$de[0];
					?>
					<img src="../<?php if($sdg[images]!=""){echo $images;}else{ echo "images/bg.jpg";} ?>" width="50%" height="auto">
				</div>
				<div class="dr_conm">

					<strong><?php echo $sdg[title]; ?></strong><span class="conf_wd all_fr">￥<?php echo $sdg2[price]; ?></span>
					<br/>
					<span class="conf_wd">颜色：<?php echo $sdg2[goodsselect]; ?></span><span class="conf_wd all_fr">x<?php echo $sdg2[number]; ?></span>
					<br/>
					<span class="conf_wd all_fr">总计：￥<?php echo ($sdg2[price]*$sdg2[number]); ?></span>
					总计：<?php echo $totalNumber2; ?>件产品</span>
				</div>

			</div>
			<?php }?>
			<div class="cy_mode" style="background: #F79DDE; border:0px;">
				收货地址：<?php echo $sdg3[address]; ?><span style=" float:right;">
				下单时间：<?php echo  $sdg3[addtime];?></span>
			</div>
		</div>
	</div>
<!-- 遮罩层 -->
<div class="mask_div">
</div>
<!-- 遮罩层 end -->
<!-- 填写快递公司及快递单号  -->
<div class="alert_div">
  <div class="alert_title">
    填写快递单号
  </div> 
  <div class="alert_line"></div>
  <div class="alert_body">
    <form id="alert_form" action="" method="post">
      <label>快递公司:</label>
      <select name="kuaidi" class="select">
        <?php foreach ($express as $v) { ?>
        <option value="<?php echo $v[id]; ?>"><?php echo $v[name] ?></option>
        <?php } ?>
      </select>
      <label>快递单号:</label><input type="text" class="text" name="danhao" value="">
      <input type="hidden" name="ordersid" id="ordersid" value="">
    </form>
  </div>
  <div class="alert_foot">
    <button type="button" class="submit" id="submit1">提交</button>
    <button type="button" class="submit" id="cancel1">取消</button>
  </div>
<input type="hidden" id="id" value="<?php echo $_REQUEST[id]; ?>">
</div>
<!-- 填写快递公司及快递单号 end -->

<!-- 商家填写回收货物地址  -->
<div class="alert_div1">
  <div class="alert_title">
    填写回收地址
  </div> 
  <div class="alert_line"></div>
  <div class="alert_body">
    <form id="alert_form1" action="" method="post">
      <label>回收地址:</label>
      <input type="text" class="text" name="address" value="">
      <input type="hidden" name="ordersid" id="ordersid1" value="">
    </form>
  </div>
  <div class="alert_foot">
    <div class="foot-div">
      <button type="button" class="submit" id="submit2">提交</button>
      <button type="button" class="submit" id="cancel2">取消</button>
    </div>
  </div>
</div>
<!-- 商家填写回收货物地址 end -->

<!-- 商家拒绝退货  -->
<div class="alert_div2">
  <div class="alert_title">
    填写拒绝退货原因
  </div> 
  <div class="alert_line"></div>
  <div class="alert_body">
    <form id="alert_form2" action="" method="post" enctype="multipart/form-data">
      <label>拒绝说明:</label>
      <textarea name="shop_comment" style="height: 150px;width: 300px;">
        
      </textarea>

      <label>说明附图:</label>
      <input type="file" class="text" name="shop_images[]" multiple>
      <input type="hidden" name="ordersid" id="ordersid2" value="">
    </form>
  </div>
  <div class="alert_foot">
    <div class="foot-div">
      <button type="button" class="submit" id="submit3">提交</button>
      <button type="button" class="submit" id="cancel3">取消</button>
    </div>
  </div>
</div>
<!-- 商家拒绝退货 end -->
</body>
<script type="text/javascript">
  // 填写快递信息 
  $('#submit1').click(function(){
    $('#alert_form').submit();
    $('.mask_div').hide();
    $('.alert_div').hide();
  });
  $('#cancel1').click(function(){
    $('.mask_div').hide();
    $('.alert_div').hide();
  })
  // 填写快递信息 end
  // 填写回收地址 
  $('#submit2').click(function(){
    $('#alert_form1').submit();
    $('.mask_div').hide();
    $('.alert_div1').hide();
  });
  $('#cancel2').click(function(){
    $('.mask_div').hide();
    $('.alert_div1').hide();
  })
  // 填写回收地址 end

  // 商家拒绝接单 
  $('#submit3').click(function(){
    $('#alert_form2').submit();
    $('.mask_div').hide();
    $('.alert_div2').hide();
  });
  $('#cancel3').click(function(){
    $('.mask_div').hide();
    $('.alert_div2').hide();
  })
  // 商家拒绝接单 end

  // 改变订单状态
  function change_orders(ordersid,state){
    var url = 'index.php?act=change&ordersid='+ordersid+'&state='+state;
    window.location.href = url;
  }
  // 改变订单状态 end

  // 改变退货状态
  function change_tuihuo(ordersid,state){
    var url = 'index.php?act=change_tuihuo&ordersid='+ordersid+'&state='+state;
    window.location.href = url;
  }
  // 改变退货状态 end

  // 接受订单 
  $('.accept').click(function(){
    var ordersid=$('#id').val();
    var state = 8;
    change_orders(ordersid,state);
  })
  // 接受订单 end

  // 拒绝订单 
  $('.refuse').click(function(){
    var ordersid=$('#id').val();
    var state = 9;
    change_orders(ordersid,state);
  })
  // 拒绝订单 end

  // 发货 
  $('.delivery').click(function(){
    var ordersid=$('#id').val();
    $('#ordersid').attr('value',ordersid);
    $('.mask_div').show();
    $('.alert_div input[type="text"]').attr('value','');
    $('.alert_div').show();
  })
  // 发货 end

  // 同意退货(商家已发货)  
  $('.agree_return').click(function(){
    var ordersid=$('#id').val();
    $('#ordersid1').attr('value',ordersid);
    $('.mask_div').show();
    $('.alert_div1 input[type="text"]').attr('value','');
    $('.alert_div1').show();
  })
  // 同意退货(商家已发货) end

  // 同意退货(商家未发货) 
  $('.agree').click(function(){
    var ordersid=$('#id').val();
    var state = 5;
    change_tuihuo(ordersid,state);
  })
  // 同意退货(商家未发货) end

  // 拒绝退货 
  $('.refuse_return').click(function(){
    var ordersid=$('#id').val();
    $('#ordersid2').attr('value',ordersid);
    $('.mask_div').show();
    $('.alert_div2 input[type="text"]').attr('value','');
    $('.alert_div2').show();
  })
  // 拒绝退货 end

  // 商家确认回收 
  $('.recover').click(function(){
    var ordersid=$('#id').val();
    var state = 5;
    change_tuihuo(ordersid,state);
  })
  // 商家确认回收 end
</script>
</html>
